package com.ts.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ts.mapper.UserMapper;
import com.ts.pojo.User;
import org.apache.tomcat.util.digester.Digester;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.List;
import java.util.UUID;

@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;

    @Override
    public String login(User user) {
        //把前端传过来的密码加密，然后再和数据库中的数据进行比。
        String password=user.getPassword();
        String md5password= DigestUtils.md5DigestAsHex(password.getBytes());
        user.setPassword(md5password);
        QueryWrapper<User> queryWrapper=new QueryWrapper(user);
        User userdb=userMapper.selectOne(queryWrapper);
        if (userdb==null){
            return null;
        }else{
            String token= UUID.randomUUID().toString().replace("-", "");
            return token;
        }
        
    }

    @Override
    public List<User> getUserList(User user) {
        List<User> list=userMapper.selectList(null);
        return list;
    }
}
